package com.wushijia.highconcurrency.future;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class CompletableFutureTest2 {

  public static void main(String[] args) throws ExecutionException, InterruptedException {
    long start = System.currentTimeMillis();
    final CompletableFuture<Integer> completableFuture = CompletableFuture.supplyAsync(() -> calculate(10));
    Thread.sleep(2000);
    System.out.println(completableFuture.get());
    long end = System.currentTimeMillis();
    System.out.println("cost:" + (end - start));
  }

  private static Integer calculate(int para) {

    try {
      Thread.sleep(2000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    return para * para;
  }


}
